import Vue from 'vue'
import VueRouter from 'vue-router'

const Home = () => import('../views/home/Home')
const Profile = () => import('../views/profile/Profile')
const Exam = () => import('../views/exam/Exam')
const News = () => import('../views/news/News')
const LogIn = () => import('../views/login/LogIn')
const SignPage =() => import('../views/signpage/SignPage')
const Help = () => import('../views/login/Help')
const ForgetPassword = () => import('../views/login/ForgetPassword')
const Problem = () => import("../views/problem/ProblemPage")
const Resolve = () => import("../views/exam/ResolvePage")
const Collect = () => import('../views/collect/collectPage')
const ExamResult = () => import("../views/exam/ExamResult")
const ExamDetail = () => import("../views/exam/ExamDetail")
const PubExam = () => import("../views/exam/PubExam")

const originalPush = VueRouter.prototype.push

//push的解决方法
VueRouter.prototype.push = function push (location) {
  return originalPush.call(this, location).catch(err => err)
}
//replace的解决方法
VueRouter.prototype.replace = function replace (location) {
    return originalPush.call(this, location).catch(err => err)
}



Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    component: () => import('../views/home/Home.vue')
  },
  {
    path: '/home',
    component: Home
  },
  {
    path: '/exam',
    component: Exam
  },
  {
    path: '/news',
    component: News
  },
  {
    path: '/profile',
    component: Profile
  },
  {
    path: '/login',
    component: LogIn
  },
  {
    path: '/register/:link',
    component: SignPage
  },
  {
    path: '/help',
    component: Help
  },
  {
    path: '/forgetpassword',
    component: ForgetPassword
  },
  {
    path: '/problem/:type',
    component: Problem
  },
  {
    path: '/resolve',
    component: Resolve
  },
  {
    path: '/collect',
    component: Collect
  },
  {
    path: '/examResult',
    component: ExamResult
  },
  {
    path: '/examDetail/:num',
    component: ExamDetail
  },
  {
    path: '/pubExam',
    component: PubExam
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
